package cn.jhc.db;

import java.nio.channels.spi.AbstractInterruptibleChannel;
import java.sql.SQLException;
import java.util.List;

import javax.management.Query;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.h2.util.New;
import org.omg.CORBA.PUBLIC_MEMBER;

import cn.jhc.bean.Article;
import jdk.internal.dynalink.beans.StaticClass;
import jdk.nashorn.internal.objects.Global;

public class ArticleDao {
    public static void add(QueryRunner runner,Article article) throws SQLException{
	  final String sql = "insert into article(title,content,publishDate,userId)"
			  +"values(?,?,?,?)"; 
	  runner.execute(sql, article.getTitle(), article.getContent(), article.getPublishDate());
    }
   public static void  del(QueryRunner runner,int id) {
	   
   }
   public static void update(QueryRunner runner,Article newArticle) {
	   
   }
   public static List<Article> fingAll(QueryRunner runner,int pageNum) {
	   final String sql = " select id,title,content, publishDate,userId from article "
			   + "order by publishDate desc light";
	   return runner.query(sql,new BeanListHandler<>(Article.class),
	   Global.PAGE_SIZE, pageNum * Global.PAGE_SIZE);
   }
   public static Article findOne(QueryRunner runner,int id) {
	   return null;
   }
   public static Article show() {
	   return null;
   }
}
